package com.huawei;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.xml.crypto.Data;
import java.io.IOException;
import java.util.Date;

@WebServlet(name = "/Cookie01" ,value="/Cookie01")
public class Cookie01 extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doGet(req, resp);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Date data = new Date();//访问时间

        Cookie cookie = new Cookie("username","lcy");
        cookie.setMaxAge(60*60*24);//cookie存活时间s为单位

        resp.addCookie(cookie);

        System.out.println("cookie-----首次访问时间-"+data);
    }
}